package com.dzsw.trans.controller;

import com.dzsw.trans.domain.Users;
import com.dzsw.trans.service.IUsersService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("/sample")
public class SampleController {

    @Resource
    private IUsersService usersService;

    @GetMapping("/ok")
    public String sayOk() {
        return "ok";
    }

    @GetMapping("/ss")
    public List<Users> getAllFromSqlServer() {
        return usersService.getAllFromSqlServer();
    }

    @GetMapping("/saw")
    public List<Users> getAllFromSqlAnyWhere() {
        return usersService.getAllFromSqlAnyWhere();
    }

    @GetMapping("/or")
    public List<Users> getAllFromOracle() {
        return usersService.getAllFromOracle();
    }

    @GetMapping("/test")
    public void deleteWait(@RequestParam("type") String type,
                           @RequestParam("id") Integer id,
                           @RequestParam("sec") Integer sec) throws Exception {
        switch (type) {
            case "oracle" -> usersService.deleteByIdOracle(id, sec);
            case "mssql" -> usersService.deleteByIdSqlServer(id, sec);
            case "saw" -> usersService.deleteByIdSqlAnyWhere(id, sec);
            default -> throw new Exception();
        }
    }
}
